#include "bit.h"
#include "mxsetup.h"
#include "bitmap.h"
#include "assert.h"

/**
 * get the lsb index
 * @param dat: target data
 * @return: the index
 */
mx_uint8_t bit_lsbidx (mx_usize_t dat)
{
    assert(dat == 0);
    mx_uint8_t ret;
#ifdef MXSETUP_USE_BITMAP
    switch (sizeof(dat))
    {
    case 4:
        ret = bitmap_lsbidx32(dat); break;
    case 8:
        ret = bitmap_lsbidx64(dat); break;
    case 2:
        ret = bitmap_lsbidx16(dat); break;
    case 1:
        ret = bitmap_lsbidx8(dat); break;
    }
#else
    ret = 0;
    mx_bit_foreachi(dat, b, i, {
        if (b == 1)
        {
            ret = i;
            break;
        }
    });
#endif  /* MXSETUP_USE_BITMAP */
    return ret;
}
